package com.daily.pump.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.daily.pump.R;
import com.daily.pump.dao.DaoSharedPreferences;
import com.daily.pump.model.SimpleWifiBean;
import com.daily.pump.widget.SwipeMenuLayout;
import com.xunxi.mimi.ui.base.BaseRecycleAdapter;
import com.xunxi.mimi.ui.base.RecycleViewHolder;
import com.xunxi.mimi.utils.LogUtil;

/**
 * Copyright (c) 2018 Miguan Inc All rights reserved.
 * Created by Liaopeikun on 2018/1/26
 * <p>
 * 可连接WiFi列表
 */
public class ScanResultWifiListAdapter extends BaseRecycleAdapter<SimpleWifiBean> {

    private int selectP = -1;

    private WifiListAdapterListener mAdapterListener;

    public void setWifiListAdapterListener(WifiListAdapterListener listener) {
        this.mAdapterListener = listener;
    }

    public ScanResultWifiListAdapter(Context context) {
        super(context);
    }

    @Override
    public void getItemView(RecycleViewHolder holder, int position, SimpleWifiBean scanResult) {
        TextView wifiTv = holder.getView(R.id.wifi_tv);
        wifiTv.setText(scanResult.wifiName);
        SwipeMenuLayout swipeMenuLayout = holder.getView(R.id.swipe_layout);
        swipeMenuLayout.setSwipeEnable(false);

        if (selectP == position) {
            wifiTv.setSelected(true);
        } else {
            wifiTv.setSelected(false);
        }

        holder.getView(R.id.content_fl).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mAdapterListener != null){
                    mAdapterListener.onItemClick(scanResult, position);
                }
            }
        });
    }

    @Override
    public int getItemResource(int viewType) {
        return R.layout.item_wifi_list;
    }

    public SimpleWifiBean setSelect(int position) {
        LogUtil.error(ScanResultWifiListAdapter.class, "setSelect setSelect:"+position);
        if (selectP != position){
            selectP = position;
            notifyDataSetChanged();
        }
        return getItem(position);
    }

    public void clearSelect() {
        if (selectP != -1){
            selectP = -1;
            notifyDataSetChanged();
        }
    }

    public interface WifiListAdapterListener{
        void onItemClick(SimpleWifiBean simpleWifiBean, int position);
    }
}
